package output;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

import organization.*;
import person.Teacher;

public class CurrConsole extends Console {

	public CurrConsole() {
		consoleStr.add("Create Lesson:");
		consoleStr.add("Get group Lessons:");
		consoleStr.add("Exit;");

	}

	public void inputInConsole() {
		Scanner scan = new Scanner(System.in);
		int opt;
		while (true) {
			while (scan.hasNextLine()) {
				if (scan.hasNextInt()) {
					opt = scan.nextInt();
					if (1 <= opt & opt <= consoleStr.size()) {
						if (opt == 1) {
							createLesson();
							getConsole();
							return;
						}
						if (opt == 2) {
							organization.Base.getGroupCurculum();
							getConsole();
							return;
						}

						if (opt == 3) {
							return;
						}
					}
					System.out.println("Incorrect point.Please enter option:");
				} else {

					System.out.println("Input incorrect!Please enter option:");
					scan.next();
				}
			}
		}
	}

	public void createLesson() {
		Auditorium audit = null;
		String name;
		Group group = null;
		GregorianCalendar time = null;

		Scanner scan = new Scanner(System.in);
		System.out.println("Please enter lesson name:");
		name = scan.nextLine();
		System.out.println("Please enter aditorium:");

		while (scan.hasNextLine()) {
			if (scan.hasNextInt()) {
				int numb = scan.nextInt();
				audit = Base.getAudObjByNumber(numb);
				break;
			} else {
				System.out.println("Should be numeric!"); // Check loops
			}
		}

		System.out.println("Please choose group:");
		ArrayList<Group> grp = new StudentConsole().getGroupList();
		if (grp != null) {
			while (scan.hasNextLine()) {
				if (scan.hasNextInt()) {
					int opt = scan.nextInt();
					if (opt > 0 & opt <= grp.size()) {
						group = grp.get(opt);
					} else {
						System.out.println("Please choose correct option.");
					}
				} else {
					System.out.println("Pelase choose from options!");
				}
			}
		} else {
			System.out.println("You can add new Group in Student console.");
			return;
		}
		Teacher teacher = new TeacherConsole().getTeachByName();

		int month = 0;
		int day = 0;
		int hour = 0;
		int minute = 0;
		int year = Calendar.getInstance().get(Calendar.YEAR);

		System.out.println("Please enter month:");
		while (scan.hasNextLine()) {
			if (scan.hasNextInt()) {
				month = scan.nextInt();
			} else {
				System.out.println("Should be numeric!");
			}
		}
		System.out.println("Please enter day:");
		while (scan.hasNextLine()) {
			if (scan.hasNextInt()) {
				day = scan.nextInt();
			} else {
				System.out.println("Should be numeric!");
			}
		}
		System.out.println("Please enter hour:");
		while (scan.hasNextLine()) {
			if (scan.hasNextInt()) {
				hour = scan.nextInt();
			} else {
				System.out.println("Should be numeric!");
			}
		}
		System.out.println("Please enter minute:");
		while (scan.hasNextLine()) {
			if (scan.hasNextInt()) {
				minute = scan.nextInt();
			} else {
				System.out.println("Should be numeric!");
			}
		}
		time = new GregorianCalendar(year, month, day, hour, minute);

		Lesson lesson = new Lesson(name, audit, group, teacher, time);
		Base.addLesson(lesson);
	}
}
